define(function (require) {

    var $ = require("zepto");
    var global = require("global");

    var media = {
        _audio: null,
        _audioNode: $(".u-audio"),
        audio_init: function () {
            if (!(0 >= media._audioNode.length)) {
                var option = {loop: true, preload: "auto", src: this._audioNode.attr("data-src")};
                this._audio = new Audio;
                for (var opt in option) {
                    if (option.hasOwnProperty(opt) && opt in this._audio) {
                        this._audio[opt] = option[opt];
                    }
                }
                this._audio.load();
            }
        },
        audio_addEvent: function () {
            function _event($audio, mode, timer) {
                mode ? $audio.text("打开") : $audio.text("关闭");
                if (timer) {
                    clearTimeout(timer);
                    $audio.removeClass("z-move z-hide");
                    timer = setTimeout(function () {
                        $audio.addClass("z-move").addClass("z-hide");
                    }, 1e3);
                }
            }
            if (this._audioNode.length > 0) {
                var $audio = this._audioNode.find(".txt_audio");
                var timer = null;
                $(this._audio).on("play", function () {
                    _event($audio, true, timer);
                    global._handleEvent("audio_play");
                }), $(this._audio).on("pause", function () {
                    _event($audio, false, timer);
                    global._handleEvent("audio_pause");
                });
            }
        },
        media_init: function () {
            this.audio_init();
            this.audio_addEvent();
        }};

    $(window).on("load", function () {
        media._audioNode.find(".btn_audio").on("click", function () {
            media._audio.paused ? media._audio.play() : media._audio.pause();
        });
    });

    return  media;
});